package main

import (
	"fmt"
	"log_process/service/Monitor"
	"log_process/service/Process"
	"log_process/service/Reader"
	"log_process/service/Writer"
	"time"
)

func main() {

	var (
		process *Process.LogProcess
		reader  *Reader.ForFileReader
		writer  *Writer.InfluxDBWriter
		monitor *Monitor.Monitor
	)

	const (
		processNumber = 2
		writerNumber  = 4
	)

	reader = &Reader.ForFileReader{
		Path: "/Users/gaoyue/logs/nginx/paiwork-access.log",
	}

	writer = &Writer.InfluxDBWriter{
		Addr:      "http://127.0.0.1:8086",
		Username:  "test",
		Password:  "123456",
		Database:  "log_process",
		Precision: "s",
	}

	process = Process.InitLogProcess(reader, writer)

	go process.Reader.Read(process.ReadChan)

	for i := 0; i < processNumber; i++ {
		go process.Process()
	}

	for i := 0; i < writerNumber; i++ {
		go process.Writer.Write(process.WriteChan)
	}

	monitor = &Monitor.Monitor{
		StartTime: time.Now(),
		Data:      Monitor.SystemInfo{},
	}

	monitor.Start(process, ":9002")

	defer func() {
		if r := recover(); r != nil {
			fmt.Printf("捕获到的错误：%s\n", r)
		}
	}()
}
